home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 50
/
Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso
/
Aminet
/
dev
/
basic
/
BlitzLstApr02.lha
/
BlitzLstApr02
/
attachments
/
mail_42
/
own2.lha
/
OwnLib.BB2
< prev
next >
Wrap
Text File
|
2000-02-16
|
8KB
|
220 lines
#VERSION = 1
#REVISION = 4
#_LVOFreeMem = -210
#_LVORemove = -252
XINCLUDE "ownlib_i.bb2" ; the library base definition
; You could use all the separate includes, or you can just stick
; amigalibs.res as a resident
; some things that are in the ASM includes, but not C includes,
; and so are not in the amigalibs.res file
#RTC_MATCHWORD = $4AFC
#RTB_AUTOINIT = 7
#RTF_AUTOINIT = (1 LSL #RTB_AUTOINIT)
#LIBB_SUMMING = 0
#LIBB_CHANGED = 1
#LIBB_SUMUSED = 2
#LIBB_DELEXP = 3
#LIBB_EXP0CNT = 4
#LIBF_SUMMING = (1 LSL #LIBB_SUMMING)
#LIBF_CHANGED = (1 LSL #LIBB_CHANGED)
#LIBF_SUMUSED = (1 LSL #LIBB_SUMUSED)
#LIBF_DELEXP = (1 LSL #LIBB_DELEXP)
#LIBF_EXP0CNT = (1 LSL #LIBB_EXP0CNT)
; !INITBYTE{offset,value}
Macro INITBYTE
CNIF `1<=255
Dc.b $A0,`1
Dc.b `2,0
CELSE
Dc.b $E0,0
Dc.w `1
Dc.b `2,0
CEND
End Macro
; !INITWORD{offset, value}
Macro INITWORD
CNIF `1<=255
Dc.b $90,`1
Dc.w `2
CELSE
Dc.b $D0,0
Dc.w `1
Dc.w `2
CEND
End Macro
; !INITLONG{offset,value}
Macro INITLONG
CNIF `1<=255
Dc.b $80,`1
Dc.l `2
CELSE
Dc.b $C0,0
Dc.w `1
Dc.l `2
CEND
End Macro
; Don't know how to do INITSTRUCT properly because it contains
; labels within the macro. These have got to be unique. Could
; do it by sticking a global label at the top of the macro and then
; using local labels, but still don't know how to get the global
; label unique :((
;size=source size 0=long, 1=word, 2=byte, 3=illegal.
;offset=offset from memory base to put data
;value=unused
;count=number of source items to copy, minus one
;follow this macro with the proper sized data (dc.b,dc.w,dc.l,etc.)
;INITSTRUCT MACRO ; &size,&offset,&value,&count
; DS.W 0
; IFC '\4',''
;COUNT\@ SET 0
; ENDC
; IFNC '\4',''
;COUNT\@ SET \4
; ENDC
;CMD\@ SET (((\1)<<4)!COUNT\@)
; IFLE (\2)-255 ;byte offset large enough?
; DC.B (CMD\@)!$80
; DC.B \2
; MEXIT
; ENDC
; DC.B CMD\@!$0C0 ;byte too small, use 24-bit offset.
; DC.B (((\2)>>16)&$0FF)
; DC.W ((\2)&$0FFFF)
; ENDM
begin: MOVEQ.l #-1,d0
RTS
; RTC_MATCHWORD indicates where RomTag-structure begins.
; Next there is poiter to the structure itself. This is meant to prevent
; interpreting any code as RomTag by mistake.
; RTF_AUTOINIT flag will make the Exec to do the initialization of jump tables for this library
; according to the tables below. (InitStuff)
ROMTag: Dc.w #RTC_MATCHWORD ; UWORD RT_MATCHWORD
Dc.l ROMTag ; APTR RT_MATCHTAG
Dc.l EndOfLib ; APTR RT_ENDSKIP
Dc.b #RTF_AUTOINIT ; UBYTE RT_FLAGS
Dc.b #VERSION ; UBYTE RT_VERSION
Dc.b #NT_LIBRARY ; UBYTE RT_TYPE
Dc.b 0 ; BYTE RT_PRI
Dc.l LibName ; APTR RT_NAME
Dc.l LibId ; APTR RT_IDSTRING
Dc.l InitStuff ; APTR RT_INIT
LibName: !LIBRARYNAME
LibId: Dc.b "own.library 1.6 (16/02/2000)",0
Even ; was ds.w 0 - you can use Even with ASM only progs, seems to work OK
InitStuff:Dc.l SizeOf.LibraryBase ; Structure size
Dc.l Functions ; Jump table address
Dc.l LibBaseData ; Information for the initialization
Dc.l InitRoutine ; Own initialization routine
Functions:Dc.l r_Open ; Open routine address
Dc.l r_Close ; Close routine address
Dc.l r_Expunge ; Expunge routine address
Dc.l r_Null ; ** Reserved **
Dc.l r_First ; First user routine address
Dc.l -1 ; Table ends
LibBaseData:!INITBYTE{SizeOf.Node\ln_Type,#NT_LIBRARY}
!INITLONG{SizeOf.Node\ln_Name,LibName}
!INITBYTE{SizeOf.Library\lib_Flags,#LIBF_SUMUSED|LIBF_CHANGED}
!INITWORD{SizeOf.Library\lib_Version,#VERSION}
!INITWORD{SizeOf.Library\lib_Revision,#REVISION}
!INITLONG{SizeOf.Library\lib_IdString,LibId}
Dc.l 0
InitRoutine: MOVE.l a5,-(a7) ; Save A5
MOVE.l d0,a5 ; Library Base address
MOVE.l a6,SizeOf.LibraryBase\libb_SysLib(a5) ; Store ExecBase to library data
MOVE.l a0,SizeOf.LibraryBase\libb_SegList(a5) ; Store SegList to library d ta
; If any other initialization operations are required put them here
MOVE.l a5,d0 ; Return the Base addres in 0
MOVE.l (a7)+,a5 ; Restore A5
RTS
.r_Open: ADDQ.w #1,SizeOf.Library\lib_OpenCnt(a6) ; New user for this library so increase ope count
BCLR #LIBB_DELEXP,SizeOf.LibraryBase\libb_Flags(a6) ; ...Expunge is forbid
MOVE.l a6,d0 ; Return BASE address in D0
RTS
.r_Close: MOVEQ #0,d0 ; Return value
SUBQ.w #1,SizeOf.Library\lib_OpenCnt(a6) ; Decrease open count
BNE 'nousers ; Is there any users?
BTST #LIBB_DELEXP,SizeOf.LibraryBase\libb_Flags(a6) ; No, so we test if there are delayed Expunge request?
BEQ 'nousers
BSR r_Expunge ; Yes! so we jump to expunge
'nousers: RTS ; Return where ever we were called from.
.r_Expunge: MOVEM.l d2/a5-a6,-(a7) ; Save registers
MOVE.l a6,a5 ; Library base address
MOVE.l SizeOf.LibraryBase\libb_SysLib(a5),a6 ; ExecBase
TST.w SizeOf.Library\lib_OpenCnt(a5) ; Library still having users?
BEQ 'nousers
BSET #LIBB_DELEXP,SizeOf.LibraryBase\libb_Flags(a5) ; Yes! -> Delayed expunge
MOVEQ #0,d0 ; We ret rn NULL
MOVEM.l (a7)+,d2/a5-a6
RTS
'nousers: MOVE.l SizeOf.LibraryBase\libb_SegList(a5),d2 ; Save SegList-address to D2
MOVE.l a5,a1
; xref _LVORemove ; And we remove the library...
JSR _LVORemove(a6) ; ... from the system list
; Any other clean up's needed? If so then do those here
MOVEQ #0,d0 ; clear D0
MOVE.l a5,a1 ; Library base
MOVE.w SizeOf.Library\lib_NegSize(a5),d0 ; Library negative size
SUB.l d0,a1 ; Points at the start of memory block
ADD.w SizeOf.Library\lib_PosSize(a5),d0 ; Add library positive size
; xref _LVOFreeMem ; nd we...
JSR _LVOFreeMem(a6) ; ... free the memory
MOVE.l d2,d0 ; Restore SegList
MOVEM.l (a7)+,d2/a5-a6
RTS
.r_Null: MOVEQ #0,d0 ; Reserved routine HAVE TO RETURN NULL IN D0
RTS
;******* Here are the user library routines *******
.r_First:
; movem.l d2-d4/a2,-(sp) ; Save any Data/Address registers exept d0,d1,a0,a1
; which can be altered freely
; Your routine code goes here
; ** Example code **
ADD.l d1,d0
; movem.l (sp)+,d2-d4/a2 ; Restore the saved registers
RTS
;**************************************************
EndOfLib: Even